package com.ruoyi.cms.controller.portal;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.cms.entity.req.MyFavoriteListReq;
import com.ruoyi.cms.entity.resp.ModelListResp;
import com.ruoyi.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.cms.service.ModelFavoriteService;

/**
 * 模型收藏
 */
@RestController
@RequestMapping("/portal/cms/favorite")
public class ModelFavoriteController {

    @Autowired
    private ModelFavoriteService modelFavoriteService;

    /**
     * 收藏
     */
    @GetMapping("/favorite")
    public R<Integer> favorite(@RequestParam Long modelId) {
        return modelFavoriteService.favorite(modelId);
    }

    /**
     * 取消收藏
     */
    @GetMapping("/cancelFavorite")
    public R<Integer> cancelFavorite(@RequestParam Long modelId) {
        return modelFavoriteService.cancelFavorite(modelId);
    }

    /**
     * 是否收藏
     */
    @GetMapping("/isFavorite")
    public R<Boolean> isFavorite(@RequestParam Long modelId) {
        return R.ok(modelFavoriteService.getFavoriteList().contains(modelId));
    }

    /**
     * 我的收藏模型作品列表
     */
    @PostMapping("/myFavoriteList")
    public R<Page<ModelListResp>> myFavoriteList(@RequestBody MyFavoriteListReq req) {
        return modelFavoriteService.myFavoriteList(req);
    }

}
